import org.lzy.shop.datas.AddAddressRequest
import org.lzy.shop.datas.DelAddress
import org.lzy.shop.datas.EditAddressRequest
import org.lzy.shop.network.KtorApiService
import org.lzy.shop.response.AddressResponse
import org.lzy.shop.viewmodel.repository.AddressRepository
import org.lzy.shop.viewmodel.repository.BaseRepository

/**
 * 地址的Repository层
 */
class AddressRepositoryImpl : BaseRepository(), AddressRepository {

    override suspend fun getAddressList(): MutableList<AddressResponse>? {
        return safeApiCall {
            val response = KtorApiService.getAddressList()
            handleResponse(response)
        }
    }

    override suspend fun addAddress(request: AddAddressRequest): String? {
        return safeApiCall {
            val response = KtorApiService.addAddress(request)
            handleResponse(response)
        }
    }

    override suspend fun updateAddress(request: EditAddressRequest): String? {
        return safeApiCall {
            val response = KtorApiService.updateAddress(request)
            handleResponse(response)
        }
    }

    override suspend fun delAddress(request: DelAddress): String? {
        return safeApiCall {
            val response = KtorApiService.delAddress(request)
            handleResponse(response)
        }
    }
}